@extends('admin._layouts.default')

@section('main')

      <div class="row-fluid ">
        <div class="span12 box gradient ">
      <div class="title">
            <div class="row-fluid">
                <h3>
                  <div class="pull-right span8 mg5" action="#">
                  <div class="pull-right input-append row-fluid">
                  <form method="get" action="{{ route('admin.customers.index') }}">
                      <div class="span4">
                    <select name="type" data-placeholder="客户类型" class="chzn-select" id="people-select">
                      <option value="0">全部客户</option>
                      <option value="1">试用客户</option>
                      <option value="2">会员客户</option>
                      <option value="4">VIP客户</option>
                      <option value="5">至尊VIP</option>
                    </select>
                    </div>
                    {{--<input type="text" class="span6" id="search-input" placeholder="城市/姓名/手机号码">--}}
                    <button type="submit" class="btn">搜索</button>
                </form>

                  </div>
                  </div>

                  <i class="fa fa-credit-card"></i> 关注客户管理


                <a href="{{ route('admin.customers.index',array('type'=>'more')) }}"  class="btn btn-danger btn-mini pull-right mg5"><i class="fa fa-thumbs-down"></i> 只看多台机器客户</a>

                </h3>
            </div>
        </div><!-- End .title -->
        <div class="content min_h500">
            <table id="datatable_in" class="responsive table table-striped" style="width:100%;margin-bottom:0; ">
              <thead>
               <tr>
                   <th width="80">
                       ID
                   </th>
                   <th width="80">
                       头像
                   </th>
                  <th width="80">
                    姓名
                  </th>
                   <th width="">
                       所属直营商
                   </th>
                  <th width="120">
                   联系方式
                  </th>
                 <th width="100">
                   身份
                 </th>
                 <th width="120">
                   可用积分/累计
                 </th>
                 @if($user->hasAccess('admin') || $user->hasAccess('city'))
                 <th>
                   积分变更
                 </th>
                 @endif
                 <th>
                    推广详情
                 </th>
                 <th>
                    装机信息
                 </th>
                 <th>
                    推荐人
                 </th>
               </tr>
              </thead>
              <tbody>
              @foreach($customers as $customer)
               <tr>
                   <td>{{ $customer->id }}</td>
                  <td>
                   <img class="thumbnail small" src="{{ $customer->avatar }}">
                  </td>
                 <td>
                    {{ $customer->name }}
                  </td>
                   <td>
                        {{ $customer->areaname->name }}
                   </td>
                 <td>
                    <i class=" icon-map-marker"></i> <strong> {{ $customer->provincename->name}} {{ $customer->cityname->name}}</strong><br/>
                    <i class=" icon-phone-sign"></i><strong>{{ $customer->mobile }}</strong>
                 </td>
                 <td>
                    @if($customer->type == 0)
                    <strong class="color_gray"><i class="fa fa-wechat"></i></strong>
                    @elseif($customer->type == 1)
                    <strong class="color_green"><i class="fa fa-wechat"></i></strong>
                    @elseif($customer->type == 2)
                    <strong class="color_info"><i class="fa fa-credit-card"></i></strong>
                    @elseif($customer->type == 3)
                    <strong class="color_blue"><i class="fa fa-certificate"></i></strong>
                    @elseif($customer->type == 4)
                    <strong class="color_orange"><i class="fa fa-heart"></i></strong>
                    @elseif($customer->type == 5)
                    <strong class="color_red"><i class="fa fa-trophy"></i></strong>
                    @endif
                    <select class="inline-block" style="width: 150px;"  onchange= "select_type('{{ $customer->id }}',this.options[this.options.selectedIndex].value)">
                        <option value="0" @if($customer->type == 0)selected @endif >关注客户</option>
                        <option value="1" @if($customer->type == 1)selected @endif>试用客户</option>
                        <option value="2" @if($customer->type == 2)selected @endif>会员客户</option>
                        {{--<option value="3" @if($customer->type == 3)selected @endif>优质客户</option>--}}
                        <option value="4" @if($customer->type == 4)selected @endif>VIP客户</option>
                        <option value="5" @if($customer->type == 5)selected @endif>至尊VIP</option>
                    </select>
                 </td>
                 <td>
                   {{ $customer->all_points-$customer->use_points }}/{{ $customer->all_points }}<a href="{{ route('admin.customers.points',array('id'=>$customer->id)) }}">(查看详情)</a>
                 </td>
                 @if($user->hasAccess('admin') || $user->hasAccess('city'))
                 <td>
                    <a class="btn btn-small" onclick="points_edit('{{ $customer->id }}','{{ $customer->all_points-$customer->use_points }}');" rel="tooltip" data-placement="left" data-original-title="点击修改" data-toggle="modal" data-target="#points_edit">点击修改</a>
                 </td>
                 @endif
                 <td>
                    <a class="btn btn-small" href="{{ route('admin.customers.affiliates',array('id'=>$customer->id)) }}" rel="tooltip" data-placement="left" data-original-title="点击查看" >点击查看</a>
                 </td>
                 <td>
                    <a class="btn btn-small" onclick="mount_show('{{ $customer->id }}');" rel="tooltip" data-placement="left" data-original-title="点击查看" data-toggle="modal" data-target="#work_out">点击查看</a>
                 </td>

                 <td>
                    {{ $customer->inviteid->name }}{{ $customer->customer_id }}
                 </td>

               </tr>
               @endforeach



               </tbody>
            </table>
                <div class="row-fluid control-group">
                 <div class="pull-left span6" action="#">
                    <div class=" ">
                      <div class="controls inline input-large pull-left">
                       <select data-placeholder="批量操作: " class="chzn-select " id="default-select">
                          <option value=""></option>
                         <option value="Bender">删除</option>
                       </select>
                     </div>
                      <button type="button" class="btn inline">执行</button>
                    </div>
                  </div>
                 <div class="span6">
                    <div class="pagination pull-right ">
                    {{ $customers->appends(array('type' => $type))->links() }}
                    </div>
                  </div>
                </div>
                <br/>
               <!-- End row-fluid -->





        </div> <!-- End .content -->


        </div>
        <!-- End box -->
      </div>


@stop



@section('modals')
<div id="work_out" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-sm">
    <div class="modal-content">
      <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 class="modal-title" id="myModalLabel">装机列表</h3>
      </div>
      <div class="modal-body">
          {{--<div class="form-row control-group row-fluid">--}}
            {{--<div class="controls span9">--}}
              {{--<div class="input-append row-fluid">--}}
                {{--<input type="text" class="span5" id="search-input" placeholder="搜索员工">--}}
                {{--<button type="submit" class="btn">搜索</button>--}}
              {{--</div>--}}
            {{--</div>--}}
          {{--</div>--}}

            {{ Form::open(array('route' => 'admin.services.paidan','id'=>'works','class'=>'form-horizontal')) }}
          <input type="hidden" name="service_id" value="" id="service_id">
          <table class="table" id="mount_info">
            <tr>
                <td>装机人</td>
                <td>装机电话</td>
                <td>装机型号</td>
                <td>装机日期</td>
                <td>状态</td>
            </tr>
          </table>
        {{ Form::close() }}

      </div>
      <div class="modal-footer">
                <div class="row-fluid control-group">
                  <div class="pull-left span6" action="#">
                    <div class="pagination pull-left ">
                    </div>
                  </div>
                  <div class="span6">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                  </div>
                </div>


      </div>
    </div>
  </div>
</div>

<div id="points_edit" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-sm">
    <div class="modal-content">
      <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 class="modal-title" id="myModalLabel">积分修改</h3>
      </div>
      <div class="modal-body">
          {{--<div class="form-row control-group row-fluid">--}}
            {{--<div class="controls span9">--}}
              {{--<div class="input-append row-fluid">--}}
                {{--<input type="text" class="span5" id="search-input" placeholder="搜索员工">--}}
                {{--<button type="submit" class="btn">搜索</button>--}}
              {{--</div>--}}
            {{--</div>--}}
          {{--</div>--}}

            {{ Form::open(array('route' => 'admin.customers.points_edit','id'=>'points_form','class'=>'form-horizontal')) }}
            <input type="hidden" id="customer_id" name="customer_id" value="">
            <input type="hidden" id="count" name="count" value="">
          <tr><th width="20px;" style="opacity: 0.6; background: rgb(51, 102, 153);">&nbsp;</th><td style="background-color: #dfdfdf;" height="130px" width="320px">
          	<table>
          		<tbody><tr>
          			<td style="line-height: 30px;" valign="top">方式：</td>
          			<td><select name="add" id="add" style="width: 120px;" class="zcsel">
          					<option value="1">充值</option>
          					<option value="0">消费</option>
          			</select></td>
          			<td style="line-height: 30px;" valign="top">数额：</td>
          			<td><input name="ccount" id="ccount" type="text" class="je" style="width: 50px;"></td>
          			</tr>
          			<tr>
          			<td style="line-height: 30px;" valign="top">行为：</td>
          			<td colspan="2"><input type="text" name="action" class="bz" style="width: 150px;"></td>
          			<td valign="top" align="right">
          			<input type="button" id="points_edit_btn" onclick="fyjs()" class="btn" value="确定">
          			</td>
          		</tr>
          	</tbody></table>
          </td><th width="20px;" style="width: 20px; opacity: 0.6; background: rgb(51, 102, 153);">&nbsp;</th></tr>
        {{ Form::close() }}

      </div>
      <div class="modal-footer">
                <div class="row-fluid control-group">
                  <div class="pull-left span6" action="#">
                    <div class="pagination pull-left ">
                    </div>
                  </div>
                  <div class="span6">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                  </div>
                </div>


      </div>
    </div>
  </div>
</div>

<div id="confirm_alert" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-sm">
    <div class="modal-content">
      <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 class="modal-title" id="myModalLabel">确定本次操作吗？</h3>
      </div>
      <div class="modal-body">
        <i class=" icon-warning-sign color_red pull-left fs_24"></i>

        <p>一旦【确定】，本次操作不可撤销。</p>

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        <button type="button" id="" class="btn btn-primary">确定</button>
      </div>
    </div>
  </div>
</div>
@stop

@section('script')
<script language="javascript" type="text/javascript" src="{{ URL::asset('web/js/plugins/jquery.peity.min.js') }}"></script>
<script language="javascript" type="text/javascript" src="{{ URL::asset('web/js/plugins/jquery.uniform.min.js') }}"></script>
<script language="javascript" type="text/javascript" src="{{ URL::asset('web/js/plugins/chosen/chosen/chosen.jquery.min.js') }}"></script>

<script language="javascript" type="text/javascript" src="{{ URL::asset('web/js/plugins/flot/jquery.flot.js') }}"></script>



<script src="{{ URL::asset('web/js/scripts.js') }}"></script>
<script language="javascript" type="text/javascript" src="{{ URL::asset('web/js/jnavigate.jquery.min.js') }}"></script>
<script>
function select_type(id,type){
    if(confirm("确定要修改此用户的级别吗？")){
        $.post('{{ URL::route('admin.customers.change') }}',{id : id ,type:type},function(data){
            if(data == 1){
                location.reload();
            }else{
                alert(data);
            }
        });
    }
}
function mount_show(id){
        var img = '<img src="{{ URL::asset('ad/img/ajax-loader.gif') }}">';
        $('#mount_info').html(img);

        $.post('{{ URL::route('admin.customers.mount_info') }}',{id : id},function(data){
            $('#mount_info').html(data);
        });
}

function points_edit(id,count){
    $('#customer_id').val(id);
    $('#count').val(count);
}
function fyjs(){
   var count = $('#count').val();
   var ccount = $('#ccount').val();
   var type = $('#add').val();
   if(type == 0 && ccount > count){
        alert('积分不够消费');
        return false
   }else{
        $('#points_edit_btn').attr("disabled",true);
        $('#points_form').submit();
   }
}
</script>
@stop
